package org.ishequ.sharedpfrefs;

import java.util.Map;

import org.ishequ.service.SettingService;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class Andriod_SharedPreferencesActivity extends Activity {
	private EditText editName;
	private EditText editAge;
	SettingService service;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); 
        editName = (EditText)findViewById(R.id.name);
        editAge = (EditText)findViewById(R.id.age);
        service = new SettingService(this);
        Map<String,String> map = service.getSettings();
        editName.setText(map.get("name"));
        editAge.setText(map.get("age"));
    }
    
    public void save(View v){
    	String name = editName.getText().toString();
    	int age = Integer.valueOf(editAge.getText().toString());
    	service.save(name,age);
    	Toast.makeText(this, R.string.success,Toast.LENGTH_SHORT).show();
    }
}